package com.lsege.controller.backstage;

import com.lsege.entity.JsonResult;
import com.lsege.entity.backstage.DeliveryProduct;
import com.lsege.mapper.backstage.DeliveryProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.util.JAXBSource;
import java.util.List;

/**
 * Created by Administrator on 2017/8/3 0003.
 */
@RestController
@RequestMapping("deliveryProduct")
public class DeliveryProductController {
    @Autowired
    DeliveryProductMapper deliveryProductMapper;

    /**
     *查看商品列表
     * @return
     */
    @GetMapping("getDeliveryProduct")
    public JsonResult getDeliveryProduct(){
        JsonResult json=new JsonResult();
        try {
            List<DeliveryProduct> list=deliveryProductMapper.getDeliveryProduct();
            json.setData(list);
            json.setSuccess(true);
            json.setMessage("获取成功");
        }catch (Exception e){
            e.printStackTrace();
            json.setSuccess(false);
            json.setMessage("获取失败");
        }
        return json;
    }

    /**
     * 修改商品
     * @param deliveryProduct
     * @return
     */
    @PostMapping("changeProduct")
    public JsonResult changeProduct(DeliveryProduct deliveryProduct){
        JsonResult json=new JsonResult();
        try {
            deliveryProductMapper.changeProduct(deliveryProduct);
            deliveryProductMapper.deleteProduct(deliveryProduct);
            json.setSuccess(true);
            json.setMessage("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            json.setSuccess(false);
            json.setMessage("修改失败");
        }
        return json;
    }
}
